package work;

import java.util.Scanner;

/*
1) 编程,求契波那契数列的第n 项
       1     1      2     3      5      8     13      21   ....
 */
public class Work01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入求契波那契数列的第几项");
        int n = scanner.nextInt();
        int result = sequence(n);
        System.out.println("契波那契数列的第"+n+"项为"+result);
    }
    static int sequence(int n){
        if(n==1 || n==2){
            return 1;
        }

        int n1=1,n2=1,temp = 0;
        for (int i=3;i<=n;i++){
            temp = n1 +n2;
            n1 = n2;
            n2 = temp;
        }

        return temp;
    }
}
